/*
 * @LastEditTime: 2023-02-28 14:36:34
 */
import { router } from "../index";
import { PlayHistory } from "../../Models/PlayHistory.Schema";
import { PlayHistoryController } from "../../Controller/PlayHistory.controller";
import { createPlayHistoryDTO, updatePlayHistorysDTO } from "../../DTO/PlayHistory.dto";

const PlayHistoryModel = new PlayHistoryController(PlayHistory);

//获取收藏夹
router.get("/playHistory", async (ctx, next) => {
  if (ctx.request.query.username) {
    const res = (await PlayHistoryModel.findByUsername(
      ctx.request.query.username.toString()
    )) as { code: number; message: string };
    ctx.body = res;
  }
});

// 创建收藏夹
router.post("/playHistory", async (ctx, next) => {
  // console.log('11111', ctx.request.body);
  ctx.body = await PlayHistoryModel.createItem(ctx.request.body as createPlayHistoryDTO);
});
// 更新收藏夹
router.patch("/playHistory", async (ctx, next) => {
  if (ctx.request.query.username)
    ctx.body = await PlayHistoryModel.updateById(ctx.params.id, ctx.request.body as updatePlayHistorysDTO);
});